package com.ephra.dao.servlet.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;

import com.ephra.commons.JsonUtils;
import com.ephra.commons.ResultMessage;
import com.ephra.dao.factory.Factory;
import com.ephra.dao.model.User;

public class Delete extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5136590244351718762L;

	public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter out=response.getWriter();
		Integer id=Integer.getInteger(request.getParameter("id"));
		String str="{\"data\":\"ERROR\"}";
		try {
			if (Factory.getUser().delete(id).getId().equals(id)) {
				str ="{\"data\":\"SUCCESS\"}";
			}
			out.println(str);
			out.flush();
			out.close();
//			RequestDispatcher rd=request.getRequestDispatcher(".jsp");
//			rd.forward(request, response);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
		this.doGet(request, response);
	}
}
